phoneme a
  vwl starttype #a endtype #a
  length 130
  FMT(vwl_lv/a, 100)           // adjusted from aa_3
endphoneme

phoneme a:
  vwl starttype #a endtype #a
  length 310
  lng
  FMT(vwl_lv/aa, 90)
endphoneme

phoneme E
  vwl starttype #e endtype #e
  length 120
  FMT(vwl_lv/e2, 100)
endphoneme

phoneme E:
  vwl starttype #e endtype #e
  length 300
  FMT(vwl_lv/ee2, 100)
endphoneme

phoneme e
  vwl starttype #e endtype #e
  length 120
  FMT(vwl_lv/e, 100)  // other alternative e_5
endphoneme

phoneme e:
  vwl starttype #e endtype #e
  length 300
  FMT(vwl_lv/ee, 100) // other alternative e_8
endphoneme

phoneme i
  vwl starttype #i endtype #i
  length 120
  FMT(vwl_lv/i, 110) // was i_6
endphoneme

phoneme i:
  vwl starttype #i endtype #i
  length 280
  FMT(vwl_lv/ii, 90) // was i_7
endphoneme


phoneme y   // English y, short Latgalian "hard i"
  vwl starttype #i endtype #i
  length 120
  FMT(vwl_lv/y)
endphoneme

phoneme y:   // Long Latgalian "hard i"
  vwl starttype #i endtype #i
  length 300
  FMT(vwl_lv/yy)
endphoneme

phoneme o
  vwl starttype #o endtype #o
  length 120
  FMT(vwl_lv/o, 90)
endphoneme

phoneme o:
  vwl starttype #o endtype #o
  length 300
  FMT(vwl_lv/oo, 75)
endphoneme

phoneme u
  vwl starttype #u endtype #u
  length 120
  FMT(vwl_lv/u, 140)
endphoneme

phoneme u:
  vwl starttype #u endtype #u
  length 300
  FMT(vwl_lv/uu, 120)
endphoneme

phoneme ai
  vwl starttype #a endtype #i
  length 280
  lng
  FMT(vdiph/aai, 100)
endphoneme

phoneme au
  vwl starttype #a endtype #u
  length 300
  lng
  FMT(vdiph/aau, 100)
endphoneme

phoneme ei
  vwl starttype #e endtype #i
  length 280
  lng
  FMT(vdiph/eei_2, 100)
endphoneme

phoneme ie
  vwl starttype #i endtype #e
  length 250
  lng
  FMT(vdiph2/ie_2, 100)
endphoneme

phoneme iu
  vwl starttype #i endtype #u
  length 250
  lng
  FMT(vdiph2/iu_2, 100)
endphoneme

phoneme ui
  vwl starttype #u endtype #i
  length 250
  lng
  FMT(vdiph/ui, 100)
endphoneme

phoneme uo
  vwl starttype #u endtype #a
  length 270
  lng
  FMT(vdiph2/ua, 100)
endphoneme

phoneme uo`     // shorter version of uo
  vwl starttype #u endtype #a
  length 150
  lng
  FMT(vdiph2/ua, 100)
endphoneme

phoneme oi
  vwl starttype #o endtype #i
  length 250
  lng
  FMT(vdiph/ooi, 100)
endphoneme

phoneme ts
  vls alv afr nolink
  voicingswitch J
  length 55
  lengthmod 1
  WAV(ustop/ts2, 60)
endphoneme

phoneme tS
  vls pla afr sib
  voicingswitch dZ
  lengthmod 2
  length 80
  WAV(ustop/tsh,40)
endphoneme

phoneme D   // louder and shorter version of d
  vcd alv stp
  voicingswitch t
  length 10
  lengthmod 5
  Vowelin f1=1  f2=1700 -300 300  f3=-100 80
  Vowelout f1=2 f2=1700 -300 300  f3=-100 80 brk

  IF PreVoicing THEN
    FMT(d/xd, 110)
  ENDIF

  IF nextPh(isPause2) THEN
    FMT(d/d_, 120)  addWav(x/d_,110)
  ENDIF

  FMT(d/d, 110) addWav(x/d,110)
endphoneme

phoneme h // more quiet version of standard h
  vls glt apr
  lengthmod 3
  ipa h

  IF nextPh(#a) THEN
    WAV(h/ha, 20)
  ELIF nextPh(#e) THEN
    WAV(h/he, 20)
  ELIF nextPh(#i) THEN
    WAV(h/hi, 20)
  ELIF nextPh(#o) THEN
    WAV(h/ho, 20)
  ELIF nextPh(#u) THEN
    WAV(h/hu, 20)
  ELIF nextPh(isPause) THEN
    WAV(h/h_, 40)  // louder for foreign words
  ENDIF
  WAV(h/h_, 20)  // no vowel following
endphoneme

phoneme j // **y**es
  liquid pal starttype #i

  IF nextPhW(isVowel) THEN
    NextVowelStarts
      VowelStart(j/j@)
      VowelStart(j/ja)
      VowelStart(j/je)
      VowelStart(j/ji)
      VowelStart(j/jo)
      VowelStart(j/ju)
    EndSwitch
    VowelEnding(j/xj, 70) // In difference with English, vowel is lengthened, not shortened
  ELSE
    Vowelout len=127      // no vowel follows
    FMT(j/xj)
  ENDIF

  IF prevPh(isPause) THEN
    FMT(j/_j)
  ENDIF
endphoneme

phoneme k
  vls vel stp
  lengthmod 2
  voicingswitch g
  Vowelin f1=0  f2=2300 200 400  f3=-100 80
  Vowelout f1=0 f2=2300 300 400  f3=-100 80  rms=20
  IF nextPh(isPause2) THEN
    WAV(ustop/k_)
  ENDIF
  IF nextPh(#i) OR nextPh(l^) THEN
    WAV(ustop/ki)
  ENDIF
  IF nextPh(l) THEN
    WAV(ustop/kl)
  ENDIF
  WAV(ustop/k_unasp, 60)   // weaker
endphoneme

phoneme c
  vls pal stp pzd
  voicingswitch J
  WAV(ustop/c, 80)
endphoneme

phoneme l
  liquid

//  IF nextPh(isNotVowel) THEN
//    ChangePhoneme(l/)
//  ENDIF

  IF nextPh(isNotVowel) THEN
    PrevVowelEndings
      VowelEnding(l/L1_@L)
      VowelEnding(l/L1_aL)
      VowelEnding(l/L1_eL)
      VowelEnding(l/L1_iL)
      VowelEnding(l/L1_oL)
      VowelEnding(l/L1_uL)
    EndSwitch

    FMT(l/l_)
    RETURN
  ENDIF

  CALL vowelstart_l

  IF prevPh(a) OR prevPh(a:) THEN
    VowelEnding(l/xl, 20) // FIXME
  ELSEIF prevPh(isVowel) THEN
    VowelEnding(l/xl, 10)
  ENDIF

  IF prevPh(isPause) THEN
    FMT(l/_l)
  ENDIF

  IF prevPh(t) THEN
    FMT(l/tl)
  ENDIF

  IF prevPh(l/) THEN
    FMT(l/l_long)    // double l, make it longer
  ENDIF

  FMT(l/l)
endphoneme

phoneme l^    // Latvian ļ, customized from standard l^
  liquid
  ipa ʎ
  lengthmod 7
  Vowelout len=60 lenadd rate
  length 100

  NextVowelStarts
    VowelStart(l^/j2@)
    VowelStart(l^/j2a)
    VowelStart(l^/j2e)
    VowelStart(l^/j2i)
    VowelStart(l^/j2o)
    VowelStart(l^/j2u)
  EndSwitch

  IF prevPh(isPause) THEN
    FMT(l^/_l^)
  ELSEIF nextPh(isPause) THEN
    FMT(l^/l^_)
  ENDIF

  FMT(l^/l^)

endphoneme




phoneme m // copied from standard m phoneme with rule for 'mm'
  vcd blb nas
  Vowelout f1=2  f2=1000 -500 -350  f3=-200 80 brk
  lengthmod 4

  IF KlattSynth THEN
    Vowelin  f1=0  f2=1000 -50 -200  f3=-200 80
    IF nextPh(isPause2) THEN
      FMT(klatt/m_)
    ENDIF
    FMT(klatt/m)
  ENDIF

  NextVowelStarts
    VowelStart(m/m@)
    VowelStart(m/ma)
    VowelStart(m/me)
    VowelStart(m/mi)
    VowelStart(m/mo)
    VowelStart(m/mu)
  EndSwitch

  IF prevPh(isNotVowel) AND nextPhW(isLiquid) THEN
    FMT(m/mj)
  ELIF prevPh(isPause) THEN
    FMT(m/_m)
  ELIF nextPh(isNotVowel) THEN
    FMT(m/m_)
  ELIF nextPh(m) THEN // m/mj has no volume change, so doubled 'mm' merges better
    FMT(m/mj)
  ENDIF
endphoneme

phoneme n- // more voiced variant of n
  vwl starttype #a endtype #a
  ipa nU+0329
  lengthmod 4
  length 140
  FMT(n/n-syl)
endphoneme

phoneme p
  vls blb stp
  lengthmod 2
  voicingswitch b
  Vowelin  f1=0  f2=1000 -50 -100  f3=-200 80
  Vowelout f1=0  f2=1000 -500 -350  f3=-300 80 rms=30
  IF nextPh(isPause2) THEN
    WAV(ustop/p_unasp_, 80)
  ENDIF
  IF nextPh(l) THEN
    WAV(ustop/pl)
  ENDIF
  WAV(ustop/p_unasp, 120)
endphoneme

phoneme R // Latvian hard r
  liquid trl
  lengthmod 6
  Vowelin  f1=0  f2=1700 -300 300  f3=-300 80
  Vowelout f1=2  f2=1700 -300 300  f3=-300 80 brk
FMT(r3/r_trill) addWav(r3/r_trill.wav, 60)
endphoneme

phoneme r // Latvian soft r
  liquid trl
  lengthmod 6
  Vowelin  f1=0  f2=1700 -300 300  f3=-300 80
  Vowelout f1=2  f2=1700 -300 300  f3=-300 80 brk
  FMT(j/j_) addWav(r3/r_trill.wav, 25)
endphoneme

phoneme s
  vls alv frc sib
  voicingswitch z
  lengthmod 3
  Vowelin  f1=0  f2=1700 -300 300  f3=-100 80
  Vowelout f1=0  f2=1700 -300 250  f3=-100 80  rms=20
  WAV(ufric/s,60)
endphoneme

phoneme t
  vls alv stp //lengthenstop
  lengthmod 1
  voicingswitch d
  IF nextPh(isPause2) THEN
    WAV(ustop/t_dnt, 40)
  ENDIF
  WAV(ustop/t_dnt, 50)
endphoneme

phoneme z`  // Shortened version of z for diphthong dz
  vcd alv frc sib
  voicingswitch s
  length 10
  lengthmod 6
  Vowelout f1=0  f2=1700 -300 300  f3=-100 60  len=50

  IF KlattSynth THEN
    Vowelin f1=0 f2=1390 -300 300 f3=0 0
    Vowelout f1=1  f2=1390 -300 300  f3=-100 60  len=50 brk
  ENDIF

  IF nextPh(isPause2) THEN
    length 20
    FMT(voc/z_, 120) addWav(ufric/s_, 95)
  ENDIF
  FMT(voc/z, 110) addWav(ufric/s_, 100)
endphoneme

phoneme Z` // Shortened version of Z for diphthong dZ
  vcd pla frc sib
  voicingswitch S
  length 30
  lengthmod 6
  Vowelin  f1=0  f2=2000 0 300  f3=-200 80
  Vowelout f1=2  f2=2000 0 300  f3=-200 80 brk

  IF KlattSynth THEN
    IF nextPh(isPause2) THEN
      FMT(klatt/zh_, 70) addWav(vocw/zh, 70)
    ENDIF
    FMT(klatt/zh) addWav(vocw/zh, 130)
  ENDIF

  IF nextPh(isPause2) THEN
    FMT(voc/zh_, 80) addWav(vocw/zh, 70)
  ENDIF
  FMT(voc/zh) addWav(vocw/zh, 130)
endphoneme

phoneme >  // lengthen previous vowel less than using ":"
  virtual
  length 20 // it actually seems working shorter, but anyway...
endphoneme

phoneme } // Tiny, 5ms non-linked pause (used between phonemes in word)
  pause
  nolink
  length 5
endphoneme




